#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023, Christopher Durand
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":platform:dac"
    module.description = "D/A converter (DACC)"

def prepare(module, options):
    device = options[":target"]
    if not device.has_driver("dacc:sam") or device.identifier.family != "e7x/s7x/v7x":
        return False

    module.depends(
        ":architecture:register",
        ":cmsis:device",
        ":math:algorithm",
        ":platform:gpio")

    return True

def build(env):
    device = env[":target"]
    env.substitutions = { "target" : device.identifier }

    env.outbasepath = "modm/src/modm/platform/dac"
    env.copy("dac.hpp")
    env.template("dac_impl.hpp.in")
